var oldLink = null;
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  return false;
}
// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field. 
 // if (cal.sel.id == "sel1" || cal.sel.id == "sel3")
 // if(cal.sel.id like "sel")
    cal.callCloseHandler();
}

function closeHandler(cal) {
  cal.hide();                        // hide the calendar
}

function showCalendar(id, format) {
  var el = document.getElementById(id);
  if (!el) {
	  el = document.all(id);
  }
  if (calendar != null) {
    calendar.hide();                 // so we hide it first.
  } else {
    var cal = new Calendar(false, null, selected, closeHandler);
    calendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    cal.create();
  }
  calendar.setDateFormat(format);    // set the specified date format
  calendar.parseDate(el.value);      // try to parse the text in field
  calendar.sel = el;                 // inform it what input field we use
  calendar.showAtElement(el);        // show the calendar below it

  return false;
}
function makeDate8(el) {
  if (el.value.indexOf("-") == -1 || el.value.length <8)
  {
	  return false;
  }
  v = el.value;
  strMonth = v.substring(v.indexOf("-") + 1,v.lastIndexOf("-"));
  strDay = v.substring(v.lastIndexOf("-") + 1);
  iMonth = parseInt(strMonth,10);
  iDay = parseInt(strDay,10);
  if (iMonth <10)
  {
	  strMonth = "0"+iMonth;
  }
  if (iDay <10)
  {
	  strDay = "0"+iDay;
  }
  strYear = v.substring(0,v.indexOf("-"));
  el.value = strYear+strMonth+strDay;
  //alert(strYear+strMonth+strDay);
  return true;
}
function makeDate6(el) {
  if (makeDate8(el)) {
	   el.value = el.value.substring(0,6);
  }
}
function makeDate10(el) {
  if (makeDate8(el)) {
	   el.value = el.value.substring(0,4) +"-"+el.value.substring(4,6)+"-"+el.value.substring(6,8);
  }
}
